package com.coment.po;

import com.coment.game.fight.Attrs;
import lombok.Getter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;

import java.util.Objects;

@Getter
public class AttrsGlobal {
    /// 属性分类hash
    @Id
    private Integer groupHash;

    @Indexed
    private final Integer userInfoId;

    /// 属性值
    public Attrs value;

    /// 属性标签
    private final Object[] tag;

    public AttrsGlobal() {
        this.userInfoId = -1;
        this.tag = null;
    }

    public AttrsGlobal(Integer userInfoId, Attrs source, Object... groupType) {
        source = (source == null) ? new Attrs() : source;
        this.userInfoId = userInfoId;
        this.value = source.obtainByType(12, 13);
        this.groupHash = obtainGroupHash(userInfoId, groupType);
        this.tag = groupType;
    }

    public static int obtainGroupHash(Integer userInfoId, Object... groupType) {
        Object[] hashParams = new Object[groupType.length + 1];
        hashParams[0] = userInfoId;
        System.arraycopy(groupType, 0, hashParams, 1, groupType.length);
        return Objects.hash(hashParams);
    }
}
